//
//  SubDsitrictCell.m
//  YunGui
//
//  Created by Hanen 3G 01 on 16/3/22.
//  Copyright © 2016年 hanen. All rights reserved.
//我的小区的cell

#import "SubDsitrictCell.h"
#import "MIneDistrictModel.h"


@interface SubDsitrictCell ()
{
    UIView   *_backView;
    CGFloat   space;
    
    UILabel  *_subdistrictNameLabel;
    UILabel  *_responsePersonLabel;
    UILabel  *_addressLabel;
    UILabel  *_creatpersonLabel;
}
@end

@implementation SubDsitrictCell

+ (instancetype)cellWithTabelView:(UITableView *)tableView
{
    static NSString *subdistrictCellID = @"subdistrictCellID";
    
    SubDsitrictCell *cell = [tableView dequeueReusableCellWithIdentifier:subdistrictCellID];
    
    if (!cell) {
        cell = [[SubDsitrictCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:subdistrictCellID];
        [cell addSubviews];
    }
    return cell;
}
- (void)addSubviews
{
    space = [UIView getWidth:10.0f];
    
    CGFloat cellH = [SubDsitrictCell cellHeight];
    _backView =[[UIView alloc] initWithFrame:CGRectMake(1.5 * space, space, kScreenWidth - 3 * space, cellH - space)];
    _backView.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:_backView];
    
    //小区名图片
    UIImageView  *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(1.5 * space, 1.5 * space, 20.0f, 20.0f)];
    imageView1.image = [UIImage imageNamed:@"Btn_Normal_Xiaoquming"];
//    imageView1.backgroundColor = BlueColor;
    [_backView addSubview:imageView1];
    
    UILabel   *nameLabel = [ViewTool getLabelWith:CGRectMake(imageView1.maxX + 5, imageView1.y, 60.0f, 20.0f) WithTitle:@"小区名:" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel];
    
    _subdistrictNameLabel = [ViewTool getLabelWith:CGRectMake(nameLabel.maxX, nameLabel.y, _backView.width - nameLabel.maxX, 20.0f) WithTitle:@"郎诗保利簏院. 大别墅" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_subdistrictNameLabel];
    
    UIImageView  *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(1.5 * space, imageView1.maxY + space, 20.0f, 20.0f)];
       imageView2.image = [UIImage imageNamed:@"Btn_Nor_Lianxiren"];
//    imageView2.backgroundColor = BlueColor;@"Btn_Normal_Diqu"
    [_backView addSubview:imageView2];
    
    UILabel   *nameLabel1 = [ViewTool getLabelWith:CGRectMake(imageView1.maxX + 5, imageView2.y, 60.0f, 20.0f) WithTitle:@"负责人:" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel1];
    
    _responsePersonLabel = [ViewTool getLabelWith:CGRectMake(nameLabel1.maxX, nameLabel1.y, _backView.width - nameLabel1.maxX, 20.0f) WithTitle:@"张全蛋" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_responsePersonLabel];
    
    UIImageView  *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(imageView2.x, imageView2.maxY + space, 20.0f, 20.0f)];
    imageView3.image = [UIImage imageNamed:@"Btn_Normal_Diqu"];
    [_backView addSubview:imageView3];
    
    UILabel   *nameLabel2 = [ViewTool getLabelWith:CGRectMake(nameLabel1.x, nameLabel1.maxY + 1.4 * space, 30.0f, 15.0f) WithTitle:@"地址:" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel2];
    
    
    _addressLabel = [ViewTool getLabelWith:CGRectMake(nameLabel2.maxX, nameLabel2.y, 120.0f, 15.0f) WithTitle:@"江苏 南京" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_addressLabel];
    
    UIImageView  *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(_backView.width - 140.0f, imageView3.y, 20.0f, 20.0f)];
    imageView4.image = [UIImage imageNamed:@"Btn_Normal_Jingzhengduishou"];
    [_backView addSubview:imageView4];
    
    UILabel   *nameLabel3 = [ViewTool getLabelWith:CGRectMake(_backView.width - 110.0f, nameLabel2.y, 50.0f, 15.0f) WithTitle:@"创建人:" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:nameLabel3];
    
    _creatpersonLabel = [ViewTool getLabelWith:CGRectMake(nameLabel3.maxX, nameLabel3.y, 60.0f, 15.0f) WithTitle:@"赵铁牛" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:_creatpersonLabel];
    
    self.numCount = [ViewTool getLabelWith:CGRectMake(200, 50, 60.0f, 15.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_backView addSubview:self.numCount];
    
}
- (void)setModel:(MIneDistrictModel *)model
{
    _model = model;
    _subdistrictNameLabel.text = model.title;
    _responsePersonLabel.text = model.m_user_name;
    _creatpersonLabel.text = model.user_name;
    
    NSString *placeStr;
    if ([model.province isEqualToString:model.city]) {
        placeStr = [NSString stringWithFormat:@"%@ %@",model.province,model.district];
    }else{
        placeStr = [NSString stringWithFormat:@"%@ %@ %@",model.province,model.city,model.district];
    }
    _addressLabel.text = placeStr;
}
+ (CGFloat)cellHeight
{
    return [UIView getHeight:105];
}
@end
